home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / var / lib / dpkg / info / cupsys.postinst < prev    next >
Encoding:
Text File  |  2007-04-04  |  12.1 KB  |  364 lines

  1. #! /bin/sh
  2. # postinst script for cupsys
  3. #
  4. # see: dh_installdeb(1)
  5.  
  6. set -e
  7.  
  8. # summary of how this script can be called:
  9. #        * <postinst> `configure' <most-recently-configured-version>
  10. #        * <old-postinst> `abort-upgrade' <new version>
  11. #        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
  12. #          <new-version>
  13. #        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
  14. #          <failed-install-package> <version> `removing'
  15. #          <conflicting-package> <version>
  16. # for details, see /usr/doc/packaging-manual/
  17. #
  18. # quoting from the policy:
  19. #     Any necessary prompting should almost always be confined to the
  20. #     post-installation script, and should be protected with a conditional
  21. #     so that unnecessary prompting doesn't happen if a package's
  22. #     installation fails and the `postinst' is called with `abort-upgrade',
  23. #     `abort-remove' or `abort-deconfigure'.
  24.  
  25. # Debconf
  26. . /usr/share/debconf/confmodule
  27.  
  28. # Default Configuration file
  29. if [ -e /etc/default/cupsys ]; then
  30.     . /etc/default/cupsys
  31. fi
  32.  
  33. case "$1" in
  34.     configure)
  35.     [ -f /etc/cups/printers.conf.save ] && mv /etc/cups/printers.conf.save /etc/cups/printers.conf
  36.     [ -f /etc/cups/classes.conf.save ] && mv /etc/cups/classes.conf.save /etc/cups/classes.conf
  37.  
  38.     # Set up lpadmin group.
  39.     if [ -z "`getent group lpadmin`" ]; then 
  40.         addgroup --system lpadmin
  41.     fi
  42.     if [ -n "`getent group lpadmin | awk -F: '{ print $4 }' | awk -F, '{ for (i=1; i <= NF; i++ ) print $i }' |grep '^root$'`" ]; then
  43.         # Bug#214746
  44.         echo "Deleting root from lpadmin group. If you use NIS/LDAP, change this manually."
  45.         deluser root lpadmin || true
  46.     fi
  47.  
  48.     # Set up cupsys user.
  49.     if [ -z "`getent passwd cupsys`" ]; then
  50.         adduser --quiet --system --no-create-home --ingroup lpadmin cupsys
  51.     fi
  52.     
  53.     # necessary for access to local parallel and usb printers
  54.     adduser --quiet cupsys lp
  55.     # necessary for access to local serial printers
  56.     adduser --quiet cupsys dialout
  57.     # necessary for web authentication
  58.     # disabled by default since lpadmin membership is sufficient
  59.     # adduser --quiet cupsys shadow
  60.     # necessary for access to printer/scanner combo devices
  61.     if [ -z "`getent group scanner`" ]; then
  62.         addgroup --system scanner
  63.     fi
  64.     adduser --quiet cupsys scanner
  65.  
  66.     if [ -d /etc/cups/certs ]; then
  67.         rm -rf /etc/cups/certs
  68.     fi
  69.     if [ -d /var/spool/cups/certs ]; then
  70.         mv /var/spool/cups/certs/* /var/run/cups/certs || true
  71.         rm -rf /var/spool/cups/certs
  72.     fi
  73.     if [ -d /var/lib/cups/certs ]; then
  74.         rm -rf /va/lib/cups/certs
  75.     fi
  76.     if [ -L /usr/share/ppd/cups-transitional-dir ]; then
  77.         rm -f /usr/share/ppd/cups-transitional-dir
  78.     fi
  79.     if [ -L /usr/share/cups/model/cups-included ]; then
  80.         rm -f /usr/share/cups/model/cups-included
  81.     fi
  82.  
  83.     [ -f /etc/cups/ppds.dat ] && mv /etc/cups/ppds.dat /var/cache/cups/ppd
  84.  
  85.     # Set up smb backend by symlinking to smbspool.
  86.     if [ -x /usr/bin/smbspool -a ! -e /usr/lib/cups/backend/smb ]; then
  87.         ln -sf /usr/bin/smbspool /usr/lib/cups/backend/smb
  88.     fi
  89.  
  90.     # Generate raw MIME handling files if they don't already exist.
  91.     if [ ! -e /etc/cups/raw.types ]; then
  92.         cat >/etc/cups/raw.types <<EOF
  93. # This file was generated by the cupsys package.  You may change it, or
  94. # reconfigure this file with dpkg-reconfigure.  If it is removed, it
  95. # will be regenerated by the package scripts.
  96.  
  97. application/octet-stream
  98. EOF
  99.     fi
  100.     if [ ! -e /etc/cups/raw.convs ]; then
  101.         cat >/etc/cups/raw.convs <<EOF
  102. # This file was generated by the cupsys package.  You may change it, or
  103. # reconfigure this file with dpkg-reconfigure.  If it is removed, it
  104. # will be regenerated by the package scripts.
  105.  
  106. application/octet-stream    application/vnd.cups-raw    0    -
  107. EOF
  108.     fi
  109.  
  110.     # Set up raw printing of application/octet-stream if desired.
  111.     db_fget cupsys/raw-print changed
  112.     if [ "$RET" = "true" ]; then
  113.         mv /etc/cups/raw.convs /etc/cups/raw.convs-convert
  114.         db_get cupsys/raw-print
  115.         if [ "$RET" = "true" ]; then
  116.         sed 's/^\s*#\s*application/application/' \
  117.             < /etc/cups/raw.convs-convert > /etc/cups/raw.convs
  118.         else
  119.         sed 's/^application/#application/' \
  120.             < /etc/cups/raw.convs-convert > /etc/cups/raw.convs
  121.         fi
  122.         rm -f /etc/cups/raw.convs-convert
  123.         db_fset cupsys/raw-print changed false
  124.     fi
  125.     # Set up backends
  126.     #db_fget cupsys/backend changed
  127.     #if [ "$RET" = "true" ] || [ -z "$2" ]; then
  128.     db_get cupsys/backend && SELECTED=$RET
  129.     list=`echo $SELECTED | sed -e 's/, /,/g'`
  130.     save_IFS=$IFS
  131.     IFS=,
  132.     (cd /usr/lib/cups/backend && rm -f http ipp lpd parallel scsi serial socket usb snmp)
  133.     for module in $list; do
  134.         ln /usr/lib/cups/backend-available/$module /usr/lib/cups/backend/$module
  135.         if [ "$module" = "ipp" ]; then
  136.         ln /usr/lib/cups/backend/ipp /usr/lib/cups/backend/http
  137.         fi
  138.     done
  139.     IFS=$save_IFS
  140.     db_fset cupsys/backend changed false
  141.     #fi
  142.  
  143.     # Assure that the special permissions of the lpd backend are also set
  144.     # for the link in /usr/lib/cups/backend/
  145.     if [ -e /usr/lib/cups/backend/lpd ]; then
  146.         chown root:lp /usr/lib/cups/backend/lpd
  147.         chmod 4754 /usr/lib/cups/backend/lpd
  148.     fi
  149.  
  150.     # In cupsys 1.2.8-0ubuntu3 the defaults for the active backends
  151.     # changed. snmp, scsi, and serial got added. So activate these
  152.     # backends.
  153.     if dpkg --compare-versions "$2" lt-nl "1.2.8-0ubuntu3"; then
  154.         for module in snmp scsi serial; do
  155.         [ -e /usr/lib/cups/backend/$module ] || \
  156.         ln /usr/lib/cups/backend-available/$module /usr/lib/cups/backend/$module
  157.         done
  158.     fi
  159.  
  160.     # In cupsys from 1.2.8-0ubuntu3 to 1.2.8-0ubuntu6 there were bugs
  161.     # which messed up the backend configuration. Reset to all backends
  162.     # being active when updating from one of these versions. Correct also
  163.     # if we update from 1.2.8-0ubuntu7 as the user can have updated from
  164.     # one of the broken versions to 1.2.8-0ubuntu7.
  165.     if dpkg --compare-versions "$2" ge "1.2.8-0ubuntu3" && \
  166.        dpkg --compare-versions "$2" lt-nl "1.2.8-0ubuntu8" ; then
  167.         for module in ipp lpd parallel scsi serial snmp socket usb; do
  168.         [ -e /usr/lib/cups/backend/$module ] || \
  169.         ln /usr/lib/cups/backend-available/$module /usr/lib/cups/backend/$module
  170.         if [ "$module" = "ipp" ]; then
  171.             [ -e /usr/lib/cups/backend/http ] || \
  172.             ln /usr/lib/cups/backend/ipp /usr/lib/cups/backend/http
  173.         fi
  174.         done
  175.     fi
  176.  
  177.     # Resync Debconf database with real state
  178.     list=`( cd /usr/lib/cups/backend && for f in ipp lpd parallel scsi serial socket usb snmp; do [ -e $f ] && echo -n "$f, "; done ) | sed -e 's/, $//'`
  179.     db_set cupsys/backend $list;
  180.  
  181.     # Create password file for Digest authentication
  182.         # (removed: Debian CUPS uses PAM and basic authentication)
  183.     #db_get cupsys/adminpassword
  184.         #VAL=$(echo -n "root:CUPS:$RET" | md5sum | cut -d' ' -f1)
  185.     #if [ -f /etc/cups/passwd.md5 ]; then
  186.         #  if [ "$(grep "^root:" /etc/cups/passwd.md5)" ]; then
  187.     #    sed -e "s/^root:lpadmin:.*/root:lpadmin:$VAL/" /etc/cups/passwd.md5 > /etc/cups/passwd.md5.$$
  188.     #    mv /etc/cups/passwd.md5.$$ /etc/cups/passwd.md5
  189.         #  else
  190.     #    echo "root:lpadmin:$VAL" >> /etc/cups/passwd.md5
  191.         #  fi
  192.     #else
  193.     #  echo "root:lpadmin:$VAL" > /etc/cups/passwd.md5
  194.     #  chown root:nogroup /etc/cups/passwd.md5
  195.     #  chmod 600 /etc/cups/passwd.md5
  196.     #fi
  197.  
  198.     # Revert to single file
  199.     if [ -f /etc/cups/cups.d/ports.conf -o -f /etc/cups/cups.d/browse.conf ]; then
  200.       perl -e 'sub readfile { local($_) = @_; open(F, $_); while (<F>) { print; } }; while (<STDIN>) { s#^Include\s+(/etc/cups/cups.d/(?:ports.conf|browse.conf))#&readfile($1)#ei; print;}' < /etc/cups/cupsd.conf > /etc/cups/cupsd.conf.$$
  201.       mv /etc/cups/cupsd.conf.$$ /etc/cups/cupsd.conf
  202.       rm -f /etc/cups/cups.d/ports.conf /etc/cups/cups.d/browse.conf
  203.       rmdir /etc/cups/cups.d 2>/dev/null || /bin/true
  204.     fi
  205.     #
  206.     # Create /etc/cups/cups.d/ports.conf and /etc/cups/cups.d/browse.conf
  207.     #db_get cupsys/ports
  208.     #VAL=$(echo "$RET" | perl -e '$ret = ""; while (<STDIN>) { chomp;
  209.     #    @values = split(/\s+/);
  210.     #    foreach(@values) {
  211.     #      if (/^\d+$/ && $_ >= 0 && $_ < 65536) {
  212.     #        # PORT
  213.     #        $ret .= "Port $_\\n";
  214.     #      } elsif (/^\d+\.\d+\.\d+\.\d+$/ || /^\d+\.\d+\.\d+\.\d+:\d+$/) {
  215.     #        # IP
  216.     #        $ret .= "Listen $_\\n";
  217.     #      } elsif (/^[a-zA-Z0-9-_.*]+$/ || /^[a-zA-Z0-9-_.*]+:\d+$/) {
  218.     #        my($tmp) = $_;
  219.     #        if (/^[a-zA-Z0-9-_.*]+:(\d+)$/) {
  220.     #          if ($1 < 0 || $1 > 65535) {
  221.     #            # ERROR
  222.     #            $ret = "";
  223.     #            last;
  224.     #          }
  225.     #        }
  226.     #        # HOSTNAME
  227.     #        $ret .= "Listen $_\\n";
  228.     #      } elsif (/^\//) {
  229.     #        # domain socket
  230.     #        $ret .= "Listen $_\\n";
  231.     #      } else {
  232.     #        # ERROR
  233.     #        $ret = "";
  234.     #        last;
  235.     #      }
  236.     #    }
  237.     #    print $ret;
  238.     #  }')
  239.  
  240.     #if [ -z "$VAL" ]; then
  241.     #  echo "Error: debconf has an invalid value. Run 'dpkg-reconfigure cupsys' again."
  242.     #  return 1
  243.     #else
  244.     #  /bin/echo -e -n "$VAL" > /etc/cups/cups.d/ports.conf
  245.     #fi
  246.  
  247.     #db_get cupsys/browse
  248.     #if [ "$RET" = "true" ]; then
  249.     #  /bin/echo "Browsing on" > /etc/cups/cups.d/browse.conf
  250.     #else
  251.     #  /bin/echo "Browsing off" > /etc/cups/cups.d/browse.conf
  252.     #fi
  253.  
  254.     # permission configuration
  255.     chown root:lp /etc/cups ; chmod 3755 /etc/cups
  256.     chown cupsys:root /etc/cups/cupsd.conf ; chmod 644 /etc/cups/cupsd.conf
  257.     chown root:lp /etc/cups/ppd ; chmod 755 /etc/cups/ppd
  258.     chown cupsys:shadow /usr/lib/cups/daemon/cups-check-pam-auth
  259.     chmod 2754 /usr/lib/cups/daemon/cups-check-pam-auth
  260.     if [ ! -d /var/run/cups/certs ]; then
  261.       mkdir /var/run/cups/certs && chown cupsys:lpadmin /var/run/cups/certs \
  262.           && chmod 511 /var/run/cups/certs
  263.     fi
  264.     if [ -f /etc/cups/classes.conf ]; then
  265.       chown root:lp /etc/cups/classes.conf ; chmod 600 /etc/cups/classes.conf
  266.     fi
  267.     if [ -f /etc/cups/printers.conf ]; then
  268.       chown root:lp /etc/cups/printers.conf ; chmod 600 /etc/cups/printers.conf
  269.     fi
  270.  
  271.     # fix permissions for upgrades which might have written cache files as
  272.     # root
  273.     if [ -d /var/cache/cups ]; then
  274.         chown -R cupsys:lp /var/cache/cups || true
  275.     fi
  276.     
  277.     # symlink snakeoil SSL certificate if present
  278.     if dpkg --compare-versions "$2" le "1.2.1-2ubuntu1" && \
  279.         [ -e /etc/ssl/certs/ssl-cert-snakeoil.pem -a \
  280.           -e /etc/ssl/private/ssl-cert-snakeoil.key -a \
  281.           -n "`getent group ssl-cert`" -a \
  282.           ! -e /etc/cups/ssl/server.crt -a \
  283.           ! -e /etc/cups/ssl/server.key ]; then 
  284.          ln -s /etc/ssl/certs/ssl-cert-snakeoil.pem /etc/cups/ssl/server.crt
  285.          ln -s /etc/ssl/private/ssl-cert-snakeoil.key /etc/cups/ssl/server.key
  286.          adduser cupsys ssl-cert
  287.     fi
  288.  
  289.  
  290.     # Remove shutdown and reboot links; this init script does not need them.
  291.     if dpkg --compare-versions "$2" lt "1.2.1-2ubuntu3"; then
  292.         rm -f /etc/rc0.d/K19cupsys /etc/rc6.d/K19cupsys
  293.     fi
  294.  
  295.     # remove shadow privilege from cupsys (admins might have manually added
  296.     # cupsys to shadow to enable the web interface in earlier versions)
  297.     if dpkg --compare-versions "$2" le-nl "1.2.2-0ubuntu2"; then
  298.         deluser --quiet cupsys shadow 2>/dev/null || true
  299.     fi
  300.  
  301.     # Add symlink to local files required by LSB
  302.     #if [ ! -e /usr/share/ppd/1-local-admin -a ! -L /usr/share/ppd/1-local-admin ]; then
  303.     #  ln -s /usr/local/share/ppd /usr/share/ppd/1-local-admin
  304.     #fi
  305.     #if [ ! -e /usr/share/ppd/2-third-party -a ! -L /usr/share/ppd/2-third-party ]; then
  306.     #  ln -s /opt/share/ppd /usr/share/ppd/2-third-party
  307.     #fi
  308.  
  309.     ;;
  310.  
  311.     abort-upgrade|abort-remove|abort-deconfigure)
  312.  
  313.     ;;
  314.  
  315.     *)
  316.         echo "postinst called with unknown argument \`$1'" >&2
  317.         exit 0
  318.     ;;
  319. esac
  320.  
  321. # dh_installdeb will replace this with shell code automatically
  322. # generated by other debhelper scripts.
  323.  
  324. # Automatically added by dh_installdocs
  325. if [ "$1" = configure ] && which install-docs >/dev/null 2>&1; then
  326.     install-docs -i /usr/share/doc-base/cupsys
  327. fi
  328. # End automatically added section
  329. # Automatically added by dh_installinit
  330. if [ -x "/etc/init.d/cupsys" ]; then
  331.     update-rc.d cupsys multiuser 19 >/dev/null
  332.     if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
  333.         invoke-rc.d cupsys start || exit $?
  334.     else
  335.         /etc/init.d/cupsys start || exit $?
  336.     fi
  337. fi
  338. # End automatically added section
  339. # Automatically added by dh_usrlocal
  340. if [ "$1" = configure ]; then
  341. (
  342.     while read line; do
  343.         set -- $line
  344.         dir="$1"; mode="$2"; user="$3"; group="$4"
  345.         if [ ! -e "$dir" ]; then
  346.             if mkdir "$dir" 2>/dev/null; then
  347.                 chown "$user":"$group" "$dir"
  348.                 chmod "$mode" "$dir"
  349.             fi
  350.         fi
  351.     done
  352. ) << DATA
  353. /usr/local/share 2775 root staff
  354. /usr/local/share/ppd 2775 root staff
  355. DATA
  356. fi
  357. # End automatically added section
  358.  
  359.  
  360. db_stop
  361. exit 0
  362.  
  363.  
  364.